
import util.PATH as PATH
import util.data_helper as data_helper

def get_train_and_eval_set(vocabulary, developers_list, bugs_msg_all, datas_ids):
	features = []
	labels = []
	for index in range(len(datas_ids)):
		name = datas_ids[index]  # 取出index位置的bug_id, 作为文件名
		feature = []
		with open(PATH.path_corpus + str(name), 'r') as reader:
			for line in reader.readlines():
				feature.append(line.strip())
		# words_to_ids = data_helper.data_padding_and_to_ids(feature, vocabulary)
		# features.append(words_to_ids)
		features.append(' '.join(feature))
		label = bugs_msg_all[name][0]  # assign_to
		try:
			label_id = developers_list.index(label)
		except ValueError:
			# 废弃...
			# 这里应该进一步加入容错机制, 将error以及上下文环境写入文件
			label_id = data_helper.UNK_ID  # 如果开发者不存在于developers列表, 则取id为-1
		labels.append(label_id)
	return features, labels